﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NetMonitor.ClassLib;

namespace NetMonitor.NetApp
{
    public partial class OptionForm : Form
    {
        /// <summary>
        /// 存储字体自定义颜色属性
        /// </summary>
        Color bigPointColor;

        public Color BigPointColor
        {
            get { return bigPointColor; }
            set { bigPointColor = value; }
        }

        /// <summary>
        /// 存储自定义字体属性
        /// </summary>
        Font bigPointFont;

        public Font BigPointFont
        {
            get { return bigPointFont; }
            set { bigPointFont = value; }
        }      

        Color lineColor;
        /// <summary>
        /// 存储线路的颜色
        /// </summary>
        public Color LineColor
        {
            get { return lineColor; }
            set { lineColor = value; }
        }

        int lineWidth = 1;
        /// <summary>
        /// 存储线路的宽度
        /// </summary>
        public int LineWidth
        {
            get { return lineWidth; }
            set { lineWidth = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public OptionForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 点击自定义字体按钮,有预览效果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_FontStyle_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                lb_Model.Font = fontDialog1.Font;
                lb_Model.Top = my_Model.Top - lb_Model.Height - 10;
            }
        }

        /// <summary>
        /// 点击自定义颜色按钮,有预览效果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_FontColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                lb_Model.ForeColor = colorDialog1.Color;
            }
        }

        
        /// <summary>
        /// 选择线路颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_LineColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                lineColor = colorDialog1.Color;
                DrawALittleLine();
            }
        }

        /// <summary>
        /// 选择线路粗细
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cb_LineWidth_SelectedIndexChanged(object sender, EventArgs e)
        {
            lineWidth = Int32.Parse(cb_LineWidth.SelectedItem.ToString());
            Refresh();
            DrawALittleLine();
        }


        /// <summary>
        /// 划预览的线路
        /// </summary>
        void DrawALittleLine()
        {
            Pen mypen = new Pen(lineColor);
            mypen.Width = lineWidth;
            Graphics g = CreateGraphics();
            g.DrawLine(mypen, 380, 190, 380, 310);
            mypen.Dispose();
            g.Dispose();
        }


        /// <summary>
        /// 根据赋值决定cb的选项,用于初始化
        /// </summary>
        /// <param name="width"></param>
        public void setCb_SelectItem(int width)
        {
            cb_LineWidth.SelectedIndex = width - 1;
        }


        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_OK_Click(object sender, EventArgs e)
        {
            bigPointColor = lb_Model.ForeColor;
            bigPointFont = lb_Model.Font;
            //lineColor = colorDialog1.Color;
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void OptionForm_Load(object sender, EventArgs e)
        {
            setCb_SelectItem(lineWidth);
            //DrawALittleLine();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            DrawALittleLine();
        }

    }
}
